<template>
  <div>
    <NavBar :title="title" />
    <div class="content-top">
      <!-- 提问 -->
      <div class="ask-edit">
        <div class="ask-firm">
          <span>{{ companyname }}</span>
        </div>
        <van-field
          v-model="postData.content"
          rows="6"
          autosize
          type="textarea"
          placeholder="请输入你要咨询的问题（默认匿名提问）"
          show-word-limit
          maxlength="200"
          style="
            border-radius: 10px;
            margin-bottom: 20px;
            font-size: 16px;
            color: #333;
            line-height: 22px;
          "
        />
        <van-button
          type="primary"
          block
          :loading="loading_submit"
          :disabled="disabled_submit"
          color="#f70"
          round
          style="font-size: 18px"
          text="提交"
          @click="onSubmit"
        ></van-button>
      </div>

      <!-- 实例 -->
      <dl class="ask-case">
        <dt>热门问题</dt>
        <dd>
          <span>1. 有五险一金吗？有双休吗？</span>
          <span>2. 入职试用期需要多久？试用工资是正式的百分之几？</span>
          <span>3. 公司的晋升空间如何？</span>
          <span>4. 公司主营业务是什么？未来行业前景如何？</span>
          <span>5. 上岗培训是怎样的？会有人指导吗？</span>
          <span>6. 企业文化是什么？</span>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import NavBar from "@/components/NavBar.vue";
import { Button, Field, Toast } from "vant";
import { PersonLoginedSubAsk } from "@/util/http";
import Global from "@/Global";

export default {
  name: "AskSub",
  components: {
    NavBar,
    [Button.name]: Button,
    [Field.name]: Field,
  },
  props: ["title", "jobid", "jobname", "companyid", "companyname"],
  mounted() {
    this.postData.companyid = this.companyid;
    this.postData.jobid = this.jobid;
    this.postData.jobname = this.jobname;
  },
  // 定义属性
  data() {
    return {
      postData: {
        companyid: "",
        content: "",
        jobid: "",
        jobname: "",
      },
      loading_submit: false,
    };
  },
  computed: {
    disabled_submit() {
      if (this.postData.content != "") return false;
      return true;
    },
  },
  // 方法集合
  methods: {
    onSubmit() {
      this.loading_submit = true;
      PersonLoginedSubAsk(this.postData).then((res) => {
        this.loading_submit = false;
        Toast(res.msg);
        if (res.result === 1) {
          setTimeout(() => {
            this.$router.go(-1);
          }, Global.setTimeout_time);
        }
      });
    },
  },
};
</script>

<style scoped>
.ask-edit {
  padding: 15px;
}

.ask-edit .ask-firm {
  display: flex;
  padding: 10px 15px;
  border-radius: 10px;
  margin-bottom: 10px;
  background-color: #fff;
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.ask-edit .ask-firm::before {
  content: "问：";
  display: flex;
  flex: 0 0 32px;
  color: #f70;
}

.ask-case {
  display: flex;
  flex-direction: column;
  padding: 15px 20px;
  margin: 0;
}

.ask-case dt {
  font-size: 15px;
  font-weight: 500;
  color: #777;
}

.ask-case dd {
  display: flex;
  flex-direction: column;
  margin: 6px 0 0;
}

.ask-case dd span {
  font-size: 12px;
  color: #888;
  line-height: 24px;
}
</style>